﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Math.Compiler.Interfaces;

namespace Math.Compiler
{
    public static class FunctionAttributeHelper
    {
        public static bool NamedAs(this IFunction func, string name)
        {
            return NamedAs(name, func.GetType());
        }
        public static bool NamedAs(this IEnumerableFunction func, string name)
        {
            return NamedAs(name, func.GetType());
        }
        private static bool NamedAs(string name, Type functionType)
        {
            var functionTypeMapping = (FunctionAttribute)functionType.GetCustomAttributes(typeof(FunctionAttribute), false).SingleOrDefault();
            if (functionTypeMapping != null)
            {
                return string.Compare(functionTypeMapping.Name, name) == 0;
            }
            return false;
        }
    }
}
